package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;

import com.burgeon.backend.EnterpriseWeChat.entity.Feature;
import com.burgeon.backend.EnterpriseWeChat.entity.VipSkinInfo;
import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class queryVipFeature extends RESTBase {
    private final static String RANGE = "20";//分页数量
    private String ip;
    private String account;
    private String password;

    public queryVipFeature(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     *
     * @return
     */

    public ArrayList<Feature> getData(String type) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(type), url);
//        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(new JSONArray(str).getJSONObject(0).getString("message"));
        }

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<Feature> features = new ArrayList<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            Feature feature= new Feature();
            feature.setId(jsonArray.getJSONArray(i).getString(0));
            feature.setName(jsonArray.getJSONArray(i).getString(1));
            features.add(feature);
        }

        return features;
    }

    private MultiValueMap Data(String type) {
        HashMap params = new HashMap();
        ArrayList colums = new ArrayList();//查询字段

        colums.add("ID");
        colums.add("NAME");

        params.put("columns", colums);

        String a = null;
        switch (type){
            case "2":
                a= "'APP_VIP_COLOR'";
                break;
            case "3":
                a= "'APP_VIP_TYPE'";
                break;
            case "4":
                a= "'APP_VIP_QUALITY'";
                break;
            case "5":
                a= "'APP_VIP_SHAPE'";
                break;
                    }
        params.put("table", a);//表名
        params.put("count","true");

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        queryVipFeature g = new queryVipFeature("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {//3125
            System.err.println(g.getData("2"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
